package fr.insta.reverse.uml.routing;

import javax.servlet.http.HttpServletRequest;

import fr.insta.reverse.uml.controller.AccueilController;
import fr.insta.reverse.uml.controller.DefaultController;
import fr.insta.reverse.uml.controller.Error404Controller;
import fr.insta.reverse.uml.controller.GuideController;
import fr.insta.reverse.uml.controller.ImageDisplayerController;
import fr.insta.reverse.uml.controller.ProjectController;
import fr.insta.reverse.uml.controller.UserManagerController;
import fr.insta.reverse.uml.webservice.GetImageUmlService;

/**
 * @author Sebastien
 * 
 * Handle the application's routing configuration
 */
public enum Route
{
	AccueilAlt(				"", 					AccueilController.class),
	Accueil(				"accueil", 				AccueilController.class),
	UserInscription(		"user/inscription", 	UserManagerController.class),
	UserConnection(			"user/connection", 		UserManagerController.class),
	UserUpdate(				"user/update", 			UserManagerController.class),
	UserAccueil(			"user/accueil", 		UserManagerController.class),
	UserDeconnection(		"user/deconnection", 	UserManagerController.class),
	ProjectCreate(			"project/create", 		ProjectController.class),
	ProjectUmlGeneration(	"project/generation", 	ProjectController.class),
	ProjectSearch(			"project/search", 		ProjectController.class),
	ProjectView(			"project/view", 		ProjectController.class),
	ProjectDownload(		"project/download", 	ProjectController.class),
	ProjectAccessRule(		"project/access", 		ProjectController.class),
	ProjectList(			"project/list",			ProjectController.class),
	GuideCreate(			"guide/create", 		GuideController.class),
	GuideRate(				"guide/rate",			GuideController.class),
	GuideDelete(			"guide/delete",			GuideController.class),

	//Image displayer
	ImageDisplay(			"project/image",		ImageDisplayerController.class),
	
	//Error 404
	Error404(				"error404",				Error404Controller.class),
	
	//Web Services
	WSGetImageUml(			"ws-getImageUml",		GetImageUmlService.class);

	private String m_strRoute;
	private Class<? extends DefaultController> m_class;

	private Route(String route, Class<? extends DefaultController> _class)
	{
		m_strRoute = route;
		m_class = _class;
	}
	
	/**
	 * Get the route 
	 * @return the route name
	 */
	public String getRoute()
	{
		return m_strRoute;
	}

	/**
	 * Call this function to retrieve an absolute link from the jspPage <br>
	 * if you want to navigate between a jsp to another jsp page
	 * @param _request the servlet request
	 * @return the absolute link of the route
	 */
	public String getAbsoluteRoute(HttpServletRequest _request)
	{
		return _request.getContextPath() + "/" + m_strRoute;
	}

	/**
	 * Get the class controller associated with with route
	 * @return the class controller associated with with route
	 */
	public Class<? extends DefaultController> getClassController()
	{
		return m_class;
	}
}